The ESEJob class represents the ESE job that is produced whenever a task is run. It provides the ability to monitor the job's status and retrieve both input and output parameters.
The job object can be used to get the values of input and output parameters. The following example will run the task and only return when the task is completed. Then the status can be checked and the output parameter values retrieved.
Task = ESE.FindTask( 'localhost', 8181, 'ese_addition' )
Job = Task.Run( a = 1, b = 2 )
Info = Job.Info()
IF ( Info.Status eq ESE.jobSucceeded ) THEN BEGIN
PRINT, Job.a ; 'a' is an input parameter
PRINT, Job.b ; 'b' is an input parameter
PRINT, Job.answer ; 'answer' is an output parameter
ENDIF ELSE BEGIN
PRINT, 'Uh oh...'
ENDELSE
When multiple asynchronous jobs are run in parallel, the "join" functionality of the ESE class can be used to wait until all the jobs have completed. In this example, one task object is acquired and then it is run multiple times.
Task = ESE.findTask( 'localhost', 8181, 'smooth_sailing' )
n = 4
jobs = objarr( n )
FOR i = 0, n - 1 DO BEGIN
jobs[ i ] = Task.Run( /ASYNC )
ENDFOR
status = ESE.Join( jobs )
IF ( min( status ) ) THEN BEGIN
PRINT, 'Jobs ran successfully.'
FOREACH j, jobs, index DO BEGIN
PRINT, 'Job[', strtrim( index, 2 ) + '] URL = ' + j.outputFile[ 'url' ]
ENDFOREACH
ENDIF ELSE BEGIN
PRINT, 'Uh oh...'
FOREACH j, jobs, index DO BEGIN
IF ( status[ index ] eq 0 ) THEN !null = j.cancel()
ENDFOREACH
ENDELSE
The for loop at lines 5 through 7 runs 4 jobs in parallel. The join at line 9 blocks execution until all 4 jobs have either completed successfully or one has failed. The join returns a status array of zeros and ones, indicating which jobs succeeded and which failed or are still running. If jobs are still running, it may be desirable to cancel them.
Note: The join method has options for reporting status changes.
The value of the specified input parameter as an IDL variable.
The value of the specified parameter as an IDL variable. Conversion from JSON to IDL is either performed by default routines or by custom routines. If the job did not complete successfully, then the return value is !null.
This method cancels a queued, submitted, or executing job. This method has no effect on jobs that are no longer running.
Task = ESE.FindTask( 'localhost', 8181, 'smooth_sailing' )
Job = Task.Run( /ASYNC )
Canceled = Job.Cancel()
Result = Obj.[ESEJob::]Cancel()
The return value indicates success or failure of the cancellation request (!true or !false).
None.
None.
GetParameter returns an ESETaskParameter object for the named parameter.
Task = ESE.FindTask( 'localhost', 8181, 'ese_addition' )
Job = Task.Run( a = 1, b = 2 )
Parameter = Job.GetParameter( 'answer' )
Result = Obj.[ESEJob::]GetParameter( Name )
Returns an ESETaskParameter object for the named parameter. If the parameter does not exist, then it returns !null.
Specifies the name of the particular parameter to return.
None.
GetParameters returns a list of ESETaskParameter objects.
Task = ESE.FindTask( 'localhost', 8181, 'ese_addition' )
Job = Task.Run( a = 1, b = 2 )
Parameters = Job.GetParameters()
Result = Obj.[ESEJob::]GetParameters( [ /NAMES ])
Returns a list of ESETaskParameter objects. If the task does not have any parameters then returns an empty list. If NAMES is set, it returns an array of parameter names, or returns !null if the task does not have any parameters.
None.
Set this keyword to return just the names of parameters instead of ESETaskParameter objects.
Returns a dictionary with all the properties of the job.
Task = ESE.FindTask( 'localhost', 8181, 'ese_addition' )
Job = Task.Run( a = 1, b = 2 )
Info = Job.Info()
Status = Info.Status
Result = Obj.[ESEJob::]Info()
The return value is a dictionary with the following fields:
None.
None.
Returns the job's JSON.
Task = ESE.FindTask( 'localhost', 8181, 'ese_addition' )
Job = Task.Run( a = 1, b = 2 )
JSON = Job.JSON()
Result = Obj.[ESEJob::]JSON()
Returns the job's status JSON as a string. This JSON contains all information the ESE system knows about the job.
None.
None.
The Monitor method provides the ability to monitor a job for job status and progress changes.
The specified callback is invoked whenever the monitor notices that the job status or progress number changed. This is useful for only asynchronous jobs.
In this example a "smooth sailing" job is monitored and its progress is printed to the IDL console:
Task = ESE.FindTask( 'localhost', 8181, 'smooth_sailing' )
Job = Task.Run( /ASYNC)
Job.Monitor, 'handleJobChange'
The callback is:
PRO handleJobChange, Job, userData
PRINT, 'Job Progress: ' + strtrim( info.Progress, 2 )
END
Obj.[ESEJob::]Monitor, Callback [, USER_DATA = value ] [, REQUESTS_PER_SECOND = double ]
None.
The name of a procedure to invoke whenever the job changes status or progress.
The number of times per second to check on the job's status. The default is 1.0.
An optional value to pass to the callback.
| IDL 8.4.1 | Introduced |